package com.example.autumn;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

class GeneratorCodes {

    public static void main(String[] args) {

        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();

        // 全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setOutputDir("E:\\Mycode\\work\\fish\\user-center\\src\\main\\java");
        globalConfig.setAuthor("Liao run");
        globalConfig.setOpen(false);
        // 不能覆盖不然以前的代码就没了
        globalConfig.setFileOverride(false);

        mpg.setGlobalConfig(globalConfig);

        // 数据源配置
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/mo_yu_ucenter?characterEncoding=utf-8&useSSL=false&useUnicode=true");
        dataSourceConfig.setDriverName("com.mysql.jdbc.Driver");
        dataSourceConfig.setUsername("root");
        dataSourceConfig.setPassword("123456");
        mpg.setDataSource(dataSourceConfig);

        // 包配置
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setModuleName("autumn");
        packageConfig.setParent("com.example");
        packageConfig.setController("controller");
        packageConfig.setMapper("mapper");
        packageConfig.setService("service");
        packageConfig.setEntity("entity");
        mpg.setPackageInfo(packageConfig);


        // 策略配置
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setEntityLombokModel(true);
        strategyConfig.setRestControllerStyle(true);

        // 多个表的时候，写多个就可以
        strategyConfig.setExclude(null);
        strategyConfig.setControllerMappingHyphenStyle(true);
//        strategyConfig.setTablePrefix(packageConfig.getModuleName() + "_");

        mpg.setStrategy(strategyConfig);

        mpg.execute();
    }
}